﻿using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;

namespace YouHP.Pages
{
    public class ViewPatient : BasePage
    {
        protected PatientRecordInfo PRInfo;
        protected UserInfo PatientUserInfo;
        protected string[] GraphGeneralPath;
        protected string[] GraphLabcheckPath;
        protected string[] GraphSymptomPath;
        protected string[] GraphTreatmentPath;
        protected int GraphGeneralPathCount;
        protected int GraphLabcheckPathCount;
        protected int GraphSymptomPathCount;
        protected int GraphTreatmentPathCount;

        protected override void ShowPage()
        {
            base.ShowPage();
            if(ErrorCount > 0) return;
            
            HandleCommon();
            if(IsPost) HandlePost();
            else HandleGet();
        }
        
        protected void HandleCommon()
        {
            
        }
        
        protected void HandlePost()
        {
            try
			{
				
			}
			catch(Exception ex)
			{
                throw ex;
			}
        }
        
        protected void HandleGet()
        {
            try
			{
                ReadData();
			}
			catch(Exception ex)
			{
                throw ex;
			}        
		}

        protected void ReadData()
        {
            int id = RequestTools.GetQueryInt("id", 0);
            if (id <= 0)
            {
                this.AddErrLine("病友页面不存在");
                return;
            }
            PRInfo = PatientBLL.Instance.GetPatientRecordInfoById(id);
            if (PRInfo.Id <= 0)
            {
                this.AddErrLine("病友页面不存在");
                return;
            }
            PatientUserInfo = UserBLL.Instance.GetUserInfo(PRInfo.PatientId);
            string[] spliter = new string[] {"|"};

            GraphGeneralPath = PRInfo.GraphGeneralPath.Split(spliter, StringSplitOptions.RemoveEmptyEntries);
            GraphLabcheckPath = PRInfo.GraphIndicatorPath.Split(spliter, StringSplitOptions.RemoveEmptyEntries);
            GraphSymptomPath = PRInfo.GraphSymptomPath.Split(spliter, StringSplitOptions.RemoveEmptyEntries);
            GraphTreatmentPath = PRInfo.GraphTreatmentPath.Split(spliter, StringSplitOptions.RemoveEmptyEntries);

            if (GraphGeneralPath != null) GraphGeneralPathCount = GraphGeneralPath.Length / 2;
            if (GraphLabcheckPath != null) GraphLabcheckPathCount = GraphLabcheckPath.Length / 2;
            if (GraphSymptomPath != null) GraphSymptomPathCount = GraphSymptomPath.Length / 2;
            if (GraphTreatmentPath != null) GraphTreatmentPathCount = GraphTreatmentPath.Length / 2;
        }
    }
}